import Vue from 'vue'
import Router from 'vue-router'
import routes from './routers'
import config from '../config'
import store from '../store'
Vue.use(Router)
const router = new Router({
  routes,
  mode: 'hash'
})

router.beforeEach((to, from, next) => {
  if (to.name === config.homeName) {
    // 清理面包屑导航数据
    store.dispatch('setBreadCrumb', { list: [], name: 0 })
  } else {
    store.dispatch('setBreadCrumb', { list: store.state.app.menuListData, name: null, path: to.path })
  }
  next()
})

router.afterEach(to => {
  window.scrollTo(0, 0)
})

export default router
